Move unit queries to function, naive choser for best resource