refactor for generic type