Refactoring and multi-stage processing