small refactoring of the js example