refactor for new db layout