after refactoring suggested by dave, but before changing return types