refactored alarm logic