Made ample use of mutexes to fix potential race conditions, add read timeouts (3s), debug info cleanup.