Order-independent scan and refactoring