updated documentation

updated documentation and added comments throughout the script for
explanation