Made sure it will now return a value if the server has been shut down as part of this script. Some minor improvements to it's efficiency in the process.
This is as they currently stand, I know there are better ways to have set these up but they've worked okay for now.