Fixed the script - it works perfectly and has been tested on my own system