major refactoring for mongodb
refactoring for mongodb