added backtracking