Move ObjectId checking as a middleware