Added comments to explain what's happening, renamed some arguments for consistency