refactor the transform function