refactoring to generic code