test cases and better error handling for delete