Import some changes from Ian's alert work