add generics, code cleanup