add customization to trimming middleware