edit writer.py, add some sub functions