fix pattern trimming