trim() bug fix, significant performance improvement