Improved error and validation handling