MAG-01 Code refactor, add comments.