Made the wait for server shutdown logic into a seperate function, and added some screen session cleanup.