Refactor client to modularize code.