Fixed Ruby's using deprecated to_hash
Refactored Code