Re-added some portions that were inadvertently overwritten from the trunk.