Lots of comments added | sme function names changed to suit their purpose