Merge change 6766

* changes:
  Don't pass references to temporary objects, and handle the case where we dont have a Surface.