completed delete and insert routine