python: scanning refactoring