initial clean up now releases after returning result instead of before