improved queue implementation