Added some logic to manage error situations giving feedback to the user.