Prevent some race conditions from happening