modularize the  JavaScript code