code refactoring

js code refactoring. the modular pattern.