other function for model, without repmat, but seems it was not the bottleneck