Restructured JavaScript code to use intro/outro