slight refactoring to reduce code size/duplication