extracting getDB function
= big refactor to not expose the pointers.
- delete Iterator properly.
- unify some of the code on cpp file.