Fix name of referred types for #338
fix #338 and other bugs in the model loader