Added test cases and reorganized response code