Restructured server code a bit