Catch errors in a better way