refactor a little bit for DB flow