Implemented ordering and fixed tests