Added previous mage code