refactored for express/mongodb use