Refactor + mongodb integration