extract the processCommandBuffer function into some more general