Most of this function looks to be a copy of ProtoModel().  Could you refactor this and pull the common code into a separate function?