first implementation of ordering, buggy