further unification and refactoring