alarm code simplified with clear comments