fixed bugs in alerts function