Statelessify mjutil

First step toward fixing #3596.

The code in this part of javascript would really need to be looked at.