finished first attempt at logic refactoring