added waiting queue and initialization function