added comments

no change in the code itself, only addition of commentaries to make code
readable, code can still be more efficient but works fine