Refactored mongo code a little