improved server code

Much less convoluted here.