Add tests, and add some deallocation management