Fixed bug where script didn't die if not run by root. Code cleanup