Fix memory leaks, adjust logging.
Tuneups.