Added some memory management code