Added some explanations to code.