refactored the arduino code