Ajax bug fix

Cleaning, and speeding up the code