Fix #1: can't add a new key during iteration

In Ruby 1.8, you could insert into hashes while iterating, but since 1.9 uses ordered hashes, this results in a RuntimeError. The simple fix is to convert the hash to an array before iteration.

This change is from http://stackoverflow.com/a/11120147/73492, but it was never reported back to the project.