make script more robust to error