Code tidying; adds some additional comments.