Minor fixes that prevent crashing on bad input.