Add missing include.
Use Sparql to perform sort, and split up OPTIONAL statement.
Merge pull request #1 from adam-vessey/7.x-fixes

7.x fixes