Extracted add, build, refine, scan into new modules.

Added _share.py for functions shared across sub-commands.