trim header and trailing space cleanup