made the script more robust.