first cleaned and improved version for arduino due