Fixing bug in script