Threads synchronization + small fixes.