Added checks to re-get element references if they have become orphaned (as can happen with dynamically changing widgets)