Fix script match algorithm