small refactoring to js