Refactor to_hash into helper