More tests, fixing memory leaks