refactored server a bit