refactor server client code into new file