Improved handling of miner difficulty & shares.

Also closes #331.