added the sorting and discard methods