Resubmitting fix for #143

This bug still exists, hence resubmitting fix proposed earlier by others.