refactor away some duplication