refactor server code, refactor to server side tests