refactoring client side handling, first test passing