correct bug in the latest function for the database, was returning earliest not latest