refined alert logic, added a simple test harness