Fix #508
Fix #538