Managin document ID with the DB, change name to in memory for clarity. Minor other fixes