adding comments and looping for memory needed