Added comments to script and made modifiticaions to make it more readable