Improved trim trailing whitespaces.