Added bagging code