Fixing sphinx documentation generation

Wrapping script bodies into def main() so that they don't execute implicitly when they are only imported.