Refactor: reduce the number of db requests