rough refactor complete