Sort inputs by order