Fixing pass by reference issue