Victor restructured ajax js, fixed errors

Ajax js has been restructured to handle further functionality changes