fixed side-effect of ptr vs pass-by-val vs ref issue