more refactoring and to_hash