improve order function