Fixed bug that caused a crash due to rootElement changing by the time the helper function was called.