Replace a number of assertions and crashes with proper error messages and exits