Reorganized and cleaned up the html/js code for better readability and
modularity