Added exception classes, refactored code to
mostly comply with PEP8. Refactored some variables.