Added pagination, improved the navigation code