Modified code that inadvertently removed the selected div