[DF-4399] Code refactor to avoid deadlocks by mutexes. Codestyle fixing.