Refactor state computation
Refactor the flow - switch to mustache templates