Improvements to Hash::expand and Hash::merge.

Because of the recursion in these functions, processing very large
arrays would take a very long time. I rewrote the functions to
eliminate any unnecessary recursion and function calls. Large arrays
are now processed much faster.
Fixed coding standard violations.
Use new style arrays and add a helper method.

Refactor out some duplicated code into a helper method. Use pass-by-ref
arguments to reduce time spent copying data into memory.