Moved core logic to script.js and cleaned up comments.