DB unit tests added and a few bug fixes.