Refactored exception classes and error logging