Fixes #3790 Slightly hacky, but I think this is correct and it should also improve performance somewhat.
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>