determines the correct highest order and adds to the end