Close server socket on shutdown
Move authorization code into separate module
Add test