Added some custom exceptions to the api. Refactored some controller code