Mage refactor