trim function modified