better checking for errors