python: some restructuring