refactored some duplicate javascript
created basic helpers for mongodb data access