Added some more memory management code