added conditions to catch errors