Encapsulating the javascript