refactored a bit and switched to Ruby 1.9+ style hashes