backtracking almost working