trq-2547 cleaned up some valgrind issues.
Fixed unit tests.