some python refactor