Added comments to understand what's happening.