added ajax sorting and pagination, refactored templates