First part of refactoring client