code for loading and trimming