improve error handling, testing for api endpoints