Rearranging, and adding middleware for mongodb