error handling + client api refactoring