fixed bugs in ordering