Solve possible memory leak by using unique pointer; rename a local parameter hiding a parameter outside local scope