fixed freeid if db is empty/new