[DB] Refactor code.