Add some logs and tracking for threads. New function for tracking a monitoring threads.
Fix last commit and merge with upstream version.