fix trimming, add test script