functions.js cleanup. Refactored scenario load logic.