Refactored alarms code and improved alarm injection