Fix return by ref issues