Updated MagLoop controller code