use a proper queue length
fix a memory leak