Fixed ObjectId cast, added tests