added logic to reject bad requests and read response