moved alert to top of event handler