Refactor db.transform functions