Added some comments to make code more readable.