Re-organized Javascript. Fixed state/transition expansion