Fixed some error cases