major refactor for ajax call