Fixed error message detection and added an error message callback.