Proof of work related refactor

Continues #3839