Refactor to simplify the processing process