Improve state management in GenJSCode