refactored. using hashes as output