Fix some bugs when turning the alarm on and off