refactor out structs to h, sprinkle some comments in between