Copied the code from my hacked prototype.