Add some error handluing to C