Add some extra error handling for invalid input.