begin restructuring logic into more maintainable pieces