Moved model code to modelcontext.js