corrected pass by reference bugs