Re-factoring code to handle recursive creation of models