added ajax calls and splitted js code