Added global mutex, should solve segfaults due to sync problems under heavy load