Added proper error codes and response