Added some comments to make code clearer