Comments added

add comment to most of the logic