changed trim to work on really large datasets