Misc fixes to faulty code