Fixed concurrency bugs, eliminated the use of offsetof, which gave errors on MacOS, plus other minor changes