done first draft. added some comments to interesting lines.