Various fixes to improve stability