Fixing weighted gradient