Fix issues with return-by-value