Added some custom exceptions and handling.