Refactored code shared between transform and filter