Working on queue algorithm