Fixed DB-2608 -- some memory problems found with valgrind