Refactors server code