Fixed backtracking for adding a match