Improve error messages and handling