Fixed script (more robust)