Fix #1022: divide by zero panic