Maintains state variable ordering

when code generating.  Surprisingly easy.  Closes #798