improve JavaScript

Some JaveScript improvements to clean the code.