My edit to the original Tregmine source code