updated ajax logic