Replaced mutexes with safer std::lock_guard