refactored to use mongodb