Added more comments about what the code is doing