more python refactoring