Add more input validation

Totally agree. I'll create a separate issue.