Third bulk of refactoring. Client-side.

Signed-off-by: Kirill Enykeev <enykeev@gmail.com>