Implemented backtracking!!!