latest working state

Lastest working state of the script with full functionality. Comments
need to be changed/ to be made helpful. Manual optional