converted the program from Python2 to Python3, general tidy up

changed variable names, added comments and removed unnecessary codelines