update the printing programme and sorting logic