move model code out into separate library