js refactor for maps