make script more robust to problems