Refactor MagicKernel class