Error handling

Changed the error codes to make error handling a little more coherent