fix #653 and #660