small python refactoring