removed some dead code and updated the response to handle errors better