Refactor #to_hash based on @efatsi's suggestion -- thanks!