changed ruby code to work correctly with a hash