fix up various errors in tests
fix memory issues