added lots of comments
Did some time complexity analysis.

no major fixes.