Code for generating ajax requests to separate file.
Some cleanup