code cleanup, moved db specific stuff into model.js
added clientside check