Added trimming function