Added refactored code for arduino