implemented ajax sync / async and did some refactoring