Need to deal with generics / type variables correctly (not fully done)