Order-independent scan and refactoring. WIP.