Added comments to explain whats going on.