Optimized code. Also, alerts now poll every 5 seconds for new data