Complete Fix

Made changes in the script to handle errors.