solved some bugs
refactoring ajax calls