Backtracking, approaching from more functional standpoint