Rewrote 5a to use sortappend.