fixed a bug which caused random crashes in a multi threaded environment