Add some docs; better sorting function.