refactor ui flow