Made code more readable/more comments and minor fixes