actually implement clear_error
move clearing error to the caller's responsibility
Found and fixed double free bug
holy fuck it works