added rudimentary backtracking
added rudimentary backtracking