Merge pull request #5174 from Zuhayr/mining

Stage one of Mining overhaul.