Fixed backtrack algorithm nasty bug