Introducing generic functions bufferProcessor and bufferProcessorLoop and specialising functions queueProcessor and queueProcessorLoop.