added genId to create unique(hopefully) id's for each item in the database. I also solved the memory leak on writes