improved the code with the showMessage function