Added documentation and cleanup for main.js