Added some debug logging. Fixed a potential memory leak