Aligned with pull request #390, for better performances