refactoring javascript with quint testing