Fixed the nested Ajax-call problem.

Re-wrote alot of the JS.