Quick comment: It is rarely good to return a hash. This has come up before. Even though this will probably not prove to be a bottleneck in your program. It is still a wasteful use of resources. When you return a hash, the hash is copied into the assigned variable. bad idea. You should just return a reference like this: