refactored from talk with mike h