Fixed possible segfaults from bad input.