Added exact '0' gradients for "dead-end" paths that don't end in 'out'.

This prevents dead-end paths from having to compute their gradients and values which can lead to errors if their inputs are no longer consistent.