refactor client API + bug fixes