updated code to clear the data if successfully added