updated sorted method