make script more resilient