add back in the missing stuff from the previous version of the script to complete it.