refactoring the server to be a little more readable