Added error message handling