Unit system fixes

with the second patch, autodiff converges, but there are still some small differences to the old parser,. I'll investigate. The first patch is rather cosmetic.