Code rewriting to add BFGMiner/CGMiner support