Server main thread, some minor changes