refactor js file

use module pattern