Refactoring client by encapsulating code and making it more clear