Fix multiple critical errors