Corrected generic queue implementation