refactor and mongodb

-refactored the server code.
-added mongo db support