Some code cleanup and hardening against Legacy instances