Fix bugs related to renaming generic types

Handle #488 and #620.