Seperated javascript from main file, added tons of comments and seperated a lot of routeines into functions.