Use faster ruby methods

Use Hash#each_key instead of Hash#keys.each and String#tr instead of String#gsub.