cache the results of Hash#[]
removed unnecessary groupings in regular expressions