fixing rendering loop