Attemp to make script more robust