Cleaned up codes and adding tests and clearing reverse ordering when unscope(order) is
called.