refactor trimming