Added some error handling for the controller