added logic for sample from database