completed refactor; tests fixed