Refactored main.js to minimize references to Dom elements. Reduces complexity and room for error.