Added order mode. Did some refactoring.