js extract & refactor