updated trim function