Final logic changes are done

Final logic changes are done
Added comments to the files.

Added comments to the files.