Refactor: using ordering trick, suggested by Wikipedia