Refactored buzzer code