fixes and refactors. move ensureWorking() back into thread, necessary to maintain thread state (for now). fix mining history. import State before copying.