Fixed wrong return value and missing member copy.

Fixes issue 2965.
(cherry picked from commit c6df48f823f61d55762f75dc34747816172fee02)