Implemented JQuery ajax for loading and refactored a lot