Update hmmwriter.py

refactor and clean up a bit, and add insert state