Fixing pass-by-reference exception