let's move some of this to cpp to make it a bit easier