magic function bug fixed