Added notes to code to help clarify.