I hate to be nitpicking on such an excellent PR that has already been sitting in the pipeline for a little while, but I must admit that I am having a hard time following the code (because it is technical and I am dense, not because it is poorly written).

I might help of the names were a bit more explicit. 'bt', and 'bt.dm' don't tell me what they are. Would you mind renaming them?