fixed trim function