refactored. using hashes as output

refactored. using hashes as output