Separated code into methods and added a more logical hash creation.