Removed pass ints by refernce and optimized mod function again
Updated to use pass by reference rather than pass by value