refine delete code + error reporting