Added custom exceptions and error handling