added more comments to describe each step in detail