pretty substantial refactor, grouping functionality within reasonable types.