use pass by reference rather pass by value

Changed various function parameters to use pass by reference rather
then pass by value to minimise resources overhead.