refactored the ajax navigation code