fixed bugs in reorder factors