added StateImpl for refactoring state.

fixed bug where gen was used in State rather than
StateImpl