Small refactoring of JS