Added comments explaing functionality.