halfway refactored