added beter error catching