Add some debug messages; fix memory leak