Pass by reference instead of pass by copy.
Fixed a infinite loop
Minor changes in programme