Major refactoring of API client