some internal refactoring