Refactor the ajax component