fixed memory errors in cv