Lots of small fixes to improve stability