Refactoring of alert and messaging code