Refactored handler, catch exceptions, response codes