corrected error sampling data from the database