fixed some memory errors in tests. There are still more errors