Updated to correctly work reference variables and overloaded funcitons