added more detailed header and comments to explain code