merged remaining parts from ArduinoDue branch