Added better error handling for bad requests