make script a little more robust