Improved error handling of invalid inputs.