Fixed trim function