refactored alert limits and cleaned up code by removing unnecessary loops