non-recursive backtracking until I can figure out the best way to make it recurse