Lots of small fixes