working on backtracking function