twsearch.py and twstream.py: refactoring