JS variable scope bug.