Refactored fillMagicFields method