moved script from html to js, more code cleanup.