refactor out some bits