database stuff, unique ids and dirty flags preparing for syncing