add safer check for end of db inserts