Fix #309
Implement #291