Added more exception handaling