Switch to native JavaScript

Switch to native JavaScript. Closure added to prevent from collapsed functions on return.