refactoring into magic.core