Added more detailed comments on code