minimally refactored