Reworked alarm code