add more comments, now has some actual loop logic