Fix 'IndexError: list index out of range' (patch from @Eownis)