Better thread management

ServerCore no longer runs statically, and main thread now waits until
notification by window close.