refactored and stripped down