update function to use return value optimization