added logic for adding and retrieving posts from mongodb and some refactoring