refactor all state manipulation to state module