some generic refactoring