Added mergesort algorithm

- also added a general purpose free-item-memory function