Added Sorting

Fully developed sorting options and added more detailed comments to
functions in functions.php