Updated comments, fixed bugs, added mag.js and magTest.js