Refactoring away some duplication