refactor the backtracker implementation