fixed trim function bug