Refactor to send result to js as array of results