Tweak the middleware to support MongoMapper, remove mongoid gem dependency