Correct various syntax and runtime errors