refactor to allow both normal beforeRender and customizeBeforeRender