Update script to prevent endless running loop