Documented and Cleaned Up main.js