implemented a generic backtracking generator