trimming function complete