fixed bugs in magic.py