Added comments and amde small adjustments for clarity.