Added some comments to improve code readability