Fix race condition in rendering