Refactoring the LED code