Fixing pass by reference issues