Refactor state update code
Add delete and terminate endpoints