tidied up the ajax code