HACK! Add regular flushing of module state.

This is not the right way to do it, since now there is a slight possibility
of two threads flushing the state concurrently, resulting in a big mess.