Fixed serialization issue and removed use of deprecated MongoDB APIs