moving logic into mean.js