First draft search() and sample() implementation