working version with ajax - before refactoring