Factored out db opertions
Fixed jshint errors