Seperated html and javascript, commented more and renamed things to make code more readable. Other small changes as well