Fixed bug and added error code to be sent in exceptions