revised error handling of api functions and made response format uniform