REFACTOR to use mongodb