refactor alert method