almost final impl. Missing resource release.