fix error message extraction
fix memory leaks