improved error hanling