Split the one-file script into several files

No function have been modified, I just moved them. The interface of the
single file is emulated by star imports in the __init__.py for test
purpose.