More parameter passing fixes. Fix return by reference. Add type functions