Added backtracking functionality (Untested)