handle deleted orders
reorganize code