Improved the code to display the error to user