Fix #518, fix #529