Added some debug.
Fixed a minor yet serious memory error.