Updated alert handling code and relocated the sections.