moved model function into an external lib file