Additional refactoring, added new logic to alert