Fixed race condition in entity preparation