remedied exception if key was not in the result when printing
restructure printing code, removed unnecessary redundancy from main