Optimized code and added parse_response to api functions