re-ordering function