rewrote sort library