made a few modifications to the script added by DN