Bug fixes to return value calculations