Refactoring egli_model function