moved inQueue function inside calling function