Initial fork, and amend changes into the SMD version **UNTESTED**