Update magic.py

Still not particularly functional.  There's a bug somewhere that I'm trying to figure out the location of.