Add more input validation

I think that seems like a good idea, but it would be better to do that in a separate PR dedicated to that issue.