added comments to functions and made some minor changes