Improved model joining code