refactoring + bugfix on trimming