some radical refactoring