Improving the code of the trimming and add comments.