correctly handle errors