Refactor to support mongo