improvements to the erro handling