added error handling for bad requests