Added some more comments to better explain functions and their purpose.