Fixed ajax logic