non tested backtrack algorithm oh god