mods to hmm , makes it write output after every iteration