added N-based trimming function