Cleaned up PDF export and fixed sorting