lots of avr code fixes