bug fix and update to the script