Implemented custom exceptions. Refactored some code.