Refactoring, better testing, and more mongo