refactor js to use a single api query