split handling of alerts into several functions and use switch instead of dynamic_casts