Added typechecking for instantiation