Comments have been added to improve the readability.
Added more comments throughout.