added bad request error handling to make a little more robust