Added refactor in ajax methods