refactor for using generics