clarified part of code with comments, and reorganized code in 3 so that it makes more sense