refactor processing logic