Code Tidy - removed some redundant code and changed print statements to logging.