Added comments to explain why the code is doing this.