Refactor to add a global state