fixed the trim function