When updating the database records, first perform all update and inserts and then check the timeout for expired records -> records to be deleted.
Doing first the delete may hide records "expired but to be updated".
Credits go to Nick Altmann
Closes bug #112.