Refactor client and server code structure