Refactoring code for client program