Fix #315 and fix #316