Updated with extensive comments