PEP 8-itizing, exception handling and print statements (for debug) updated to Python 3 calling convention.