functions.js: Added comments, moved vars/functions around