Moved delete book keeping to just before the actual delete, making bug finding easier