fix #822 and ref #822 too