Moved dict to top and added comments

Moved dictionary to top before main function as it only needs to be created once. Added additional comments.