persist more state, also refactor state handling