updated error handelling