Added "graceful" shutdown that closes socket and waits for pending connections