some code cleaned, added some mutexes.