Commented the JavaScript functions for clarity