refactor db operations