improved robustness, fixed memory leak in func_popr