Made indentation changes suggested by @ninas
Made changes suggested by @ninas
Moved javascript code to separate file