Corrige bug: TypeError: %d format: a number is required, not NoneType

Fixes #586 and #587