Added handling of return values in functions