Refactor js code in libs