Refactors server message handling