improved js data function