Implemented backtracking principle