Refactored: moved more html operations out of script to html page
Cleanup