Fixed sorting

Moved sorting code to layouts/base.php to fix sorting the table