Fix issue #265
Cherry pick ef64354 to bffeb05