Various fixes to broken code