added extensive comments