The buffer needs to be flushed before enqueueing the kernel again. Further optimise the mining loop by removing the need_work bool.