working on greedy sampling; this version is NOT compilable