Fix #307 and #383