Added a lot of explanatory comments.