typechecking with type parameters
refactor