refactor with state