Fix #620 and #329