optimized trim trailing whitespaces