add output.py, refactor init function