begun refactoring server code