add generics and clean up