fixed bagging segfault bug