issue #971 , some improvements