Fully resolved issue #709.

The previous fix worked only for the specific case mentioned in the
bug report, this version works for all cases.