refactoring on the client side - separation of logic and connection