Fix #597
Fix #538