a bit of refactoring on Python