Fix some bugs when using generics.