added some more tests and improved C error handling