Refactored to use mongoose