error handling v0.9 and freeing at the finish