error message work

plus some refactoring to use global variables