Various fixes to allow building without threads