Refactored code, added comments to index.html to help explain functionality