added some comments to hopefully make code easier to figure out