Bagging functions corrected