final round of refactoring before i start putting this mess back together