Added order verification
Updated to run in a single pass.